{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "ename": "ModuleNotFoundError",
     "evalue": "No module named 'pandas'",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mModuleNotFoundError\u001b[0m                       Traceback (most recent call last)",
      "Cell \u001b[1;32mIn[4], line 2\u001b[0m\n\u001b[0;32m      1\u001b[0m \u001b[38;5;66;03m# 创建生成xmind视图\u001b[39;00m\n\u001b[1;32m----> 2\u001b[0m \u001b[38;5;28;01mimport\u001b[39;00m \u001b[38;5;21;01mpandas\u001b[39;00m \u001b[38;5;28;01mas\u001b[39;00m \u001b[38;5;21;01mpd\u001b[39;00m  \n\u001b[0;32m      3\u001b[0m \u001b[38;5;28;01mimport\u001b[39;00m \u001b[38;5;21;01mxmind\u001b[39;00m\n\u001b[0;32m      4\u001b[0m \u001b[38;5;66;03m# from xmind.core.topic import TopicElement\u001b[39;00m\n\u001b[0;32m      5\u001b[0m \u001b[38;5;66;03m# from xmind.core.marker import MarkerId  \u001b[39;00m\n",
      "\u001b[1;31mModuleNotFoundError\u001b[0m: No module named 'pandas'"
     ]
    }
   ],
   "source": [
    "# 创建生成xmind视图\n",
    "import pandas as pd  \n",
    "import xmind\n",
    "# from xmind.core.topic import TopicElement\n",
    "# from xmind.core.marker import MarkerId  \n",
    "def design_sheet1(sheet1):\n",
    "    sheet1.setTitle(\"first sheet\")\n",
    "    #创建空白主题画布\n",
    "    root_topic1 = sheet1.getRootTopic()\n",
    "    root_topic1.setTitle(\"root node\")\n",
    "    # 创建子主题，并设置名称\n",
    "    sub_topic1 = root_topic1.addSubTopic()\n",
    "    sub_topic1.setTitle(\"fitst sub node\")\n",
    "    sub_topic2 = root_topic1.addSubTopic()\n",
    "    sub_topic2.setTitle(\"second sub node\")\n",
    "    # 创建自由主题\n",
    "    # detached_topic1 = root_topic1.addSubTopic(topics_type=TOPIC_DETACHED)\n",
    "    # detached_topic1.setTitle(\"detached topic\")\n",
    "    # detached_topic1.setPosition(0,30)\n",
    "    # 创建子主题的主题\n",
    "    sub_topic1_1 = sub_topic1.addSubTopic()\n",
    "    sub_topic1_1.setTitle(\"I am sub node too\")\n",
    "def gen_sheet2(workbook,sheet1):\n",
    "    sheet2 = workbook.createSheet()\n",
    "    sheet2.setTitle(\"second sheet\")\n",
    "\n",
    "    root_topic2 = sheet2.getRootTopic()\n",
    "    root_topic2.setTitle(\"root node\")\n",
    "    # 使用另外一种方法创建子主题\n",
    "    topic1 = TopicElement(ownerWorkbook=workbook)\n",
    "    # 给子主题添加一个主题间超链接，通过指定目标主题ID即可，这里链接到第一个画布\n",
    "    topic1.setTopicHyperlink(sheet1.getID())\n",
    "    topic1.setTitle(\"redirection to the first sheet\")\n",
    "\n",
    "    # 添加超链接子主题\n",
    "    topic2 = TopicElement(ownerWorkbook=workbook)\n",
    "    topic2.setTitle(\"topic with an url hyperlikn\")\n",
    "    topic2.setURLHyperlink(\"https://www.baidu.com\")\n",
    "    # 添加子主题备注\n",
    "    topic3 = TopicElement(ownerWorkbook=workbook)\n",
    "    #topic3.setTitle(\"third node\")\n",
    "    topic3.setPlainNotes(\"notes for this topic\")\n",
    "    topic3.setTitle(\"topic with \\n notes\")\n",
    "    # 添加文件超链接主题\n",
    "    topic4 = TopicElement(ownerWorkbook=workbook)\n",
    "    topic4.setTopicHyperlink(\"./logo/logo.png\")\n",
    "    topic4.setTitle(\"topic with a file\")\n",
    "    #给子主题添加一个标签\n",
    "    topic1_1 = TopicElement(ownerWorkbook=workbook)\n",
    "    topic1_1.setTitle(\"sub topic\")\n",
    "    topic1_1.addLabel(\"a label\")\n",
    "    # 添加两个子主题\n",
    "    topic1_1_1 = TopicElement(ownerWorkbook=workbook)\n",
    "    topic1_1_1.setTitle(\"topic can add multiple markers\")\n",
    "    # 给子主题添加两个图标\n",
    "    topic1_1_1.addMarker(MarkerId.startBlue)\n",
    "    topic1_1_1.addMarker(MarkerId.flagGreen)\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "    # 把创建好的子主题添加到父主题下\n",
    "    root_topic2.addSubTopic(topic1)\n",
    "    root_topic2.addSubTopic(topic2)\n",
    "    root_topic2.addSubTopic(topic3)\n",
    "    root_topic2.addSubTopic(topic4)\n",
    "    topic1.addSubTopic(topic1_1)\n",
    "    topic1_1.addSubTopic(topic1_1_1)\n",
    "\n",
    "# 创建空白的ximind文件\n",
    "workbook = xmind.load(\"my.xmind\")\n",
    "# 1.创建第一个画布\n",
    "sheet1 = workbook.getPrimarySheet()\n",
    "design_sheet1(sheet1)\n",
    "# gen_sheet2(workbook,sheet1)\n",
    "sheet1.setTitle(\"first sheet\")\n",
    "gen_sheet2(workbook,sheet1)\n",
    "xmind.save(workbook=workbook,path=\"./xmind/test.xmind\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "ename": "NameError",
     "evalue": "name 'Workbook' is not defined",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mNameError\u001b[0m                                 Traceback (most recent call last)",
      "Cell \u001b[1;32mIn[3], line 4\u001b[0m\n\u001b[0;32m      1\u001b[0m \u001b[38;5;28;01mimport\u001b[39;00m \u001b[38;5;21;01mxmind\u001b[39;00m \n\u001b[0;32m      3\u001b[0m \u001b[38;5;66;03m# 创建一个新的工作簿  \u001b[39;00m\n\u001b[1;32m----> 4\u001b[0m workbook \u001b[38;5;241m=\u001b[39m \u001b[43mWorkbook\u001b[49m()  \n\u001b[0;32m      5\u001b[0m sheet \u001b[38;5;241m=\u001b[39m workbook\u001b[38;5;241m.\u001b[39mcreateSheet(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m示例\u001b[39m\u001b[38;5;124m\"\u001b[39m)  \n\u001b[0;32m      6\u001b[0m root_topic \u001b[38;5;241m=\u001b[39m sheet\u001b[38;5;241m.\u001b[39mgetRootTopic()  \n",
      "\u001b[1;31mNameError\u001b[0m: name 'Workbook' is not defined"
     ]
    }
   ],
   "source": [
    "import xmind \n",
    "\n",
    "# 创建一个新的工作簿  \n",
    "workbook = Workbook()  \n",
    "sheet = workbook.createSheet(\"示例\")  \n",
    "root_topic = sheet.getRootTopic()  \n",
    "root_topic.setTitle(\"根主题\")  \n",
    "\n",
    "# 添加新主题  \n",
    "new_topic = TopicElement()  \n",
    "new_topic.setTitle(\"新子主题\")  \n",
    "root_topic.addSubTopic(new_topic)  \n",
    "\n",
    "# 保存文件  \n",
    "save(workbook, \"example_updated.xmind\")"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "undefined.undefined.undefined"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
